package com.yunji.base.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunji.base.bo.StaffLocationRemoveBO;
import com.yunji.base.dao.IStaffLocationDao;
import com.yunji.base.domain.StaffLocationDO;
import com.yunji.base.mapper.IStaffLocationMapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Repository
public class StaffLocationDaoImpl extends BaseDaoImpl<IStaffLocationMapper, StaffLocationDO> implements IStaffLocationDao {
    @Override
    public boolean existsLocation(List<Long> list) {
        return lambdaQuery().in(StaffLocationDO::getLocationId, list).count() > 0;
    }

    @Override
    public void delete(StaffLocationRemoveBO removeBO) {
        remove(new LambdaQueryWrapper<StaffLocationDO>()
                .in(BeanUtils.isNotNull(removeBO.getStaffIds()),StaffLocationDO::getStaffId, removeBO.getStaffIds())
                .eq(BeanUtils.isNotNull(removeBO.getLocationId()),StaffLocationDO::getLocationId, removeBO.getLocationId()));
    }

    @Override
    public List<Long> getDeployStaffIds(Long locationId) {
        return baseMapper.selectObjs(new LambdaQueryWrapper<StaffLocationDO>().select(StaffLocationDO::getStaffId).eq(StaffLocationDO::getLocationId,locationId)
                ).stream().map(o -> (Long) o).collect(Collectors.toList());
    }
}
